/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;

namespace DaveSexton.DocProject.DocSites
{
	public sealed class TermQueryExpression : QueryExpression
	{
		#region Public Properties
		public string Term
		{
			get
			{
				return term;
			}
		}

		public override bool IsOptimized
		{
			get
			{
				return true;
			}
		}
		#endregion

		#region Private / Protected
		private readonly string term;
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="TermQueryExpression" /> class.
		/// </summary>
		public TermQueryExpression(string term)
		{
			if (term == null)
				throw new ArgumentNullException("term");

			this.term = term;
		}

		/// <summary>
		/// Constructs a new instance of the <see cref="TermQueryExpression" /> class.
		/// </summary>
		public TermQueryExpression(string term, QueryExpression parent)
			: base(parent)
		{
			if (term == null)
				throw new ArgumentNullException("term");

			this.term = term;
		}
		#endregion

		#region Methods
		public override QueryExpression Normalize()
		{
			return new TermQueryExpression(term);
		}

		public override QueryExpression Optimize()
		{
			return new TermQueryExpression(term);
		}

		public override void Evaluate(Action<QueryExpression> action)
		{
			action(this);
		}

		public override void AppendToString(StringBuilder output)
		{
			if (output == null)
				throw new ArgumentNullException("output");

			output.Append(term);
		}
		#endregion
	}
}
